<?php

namespace app\admin\service\statistics\datatable\home;

use app\admin\service\statistics\datatable\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;

/**
 * 首页进入找律师
 * Class HomeToLawyerRate
 * @package app\admin\service\statistics\datatable\home
 */
class HomeToLawyerRate extends AbstractComputeStatistician
{
    // 前置数据
    protected array $statisticians = [
        'home_count' => HomeCount::class,
        'home_to_lawyer_count' => HomeToLawyerCount::class,
    ];

    // 补齐
    use CompletionTrait;

    protected function compute(int $index)
    {
        $statisticiansData = $this->statisticiansData;

        $home_count = $statisticiansData['home_count'][$index]['value'] ?? null;

        $home_to_lawyer_count = $statisticiansData['home_to_lawyer_count'][$index]['value'] ?? null;

        if (!is_numeric($home_count) || !is_numeric($home_to_lawyer_count)) {
            return '';
        }

        return show_percentage($home_to_lawyer_count, $home_count, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}